<template>
  <div class="dashboard-container">
    <div class="app-container">
      <!-- 顶部工具栏 -->
      <page-tools :show-before="true">
        <!-- 记录统计左侧 -->
        <template slot="before">
          <span>有 {{ page.total }} 条考勤审批尚未处理</span>
        </template>
        <!-- 操作按钮 右侧 -->
        <template slot="after">
          <el-button size="mini" type="warning" @click="$router.push('/import')">导入</el-button>
          <el-button size="mini" type="primary" @click="tips">提醒</el-button>
          <el-button size="mini" type="danger" @click="setting">设置</el-button>
          <el-button size="mini" type="info" @click="$router.push('archiving')">历史归档</el-button>
          <el-button size="mini" type="success" @click="$router.push('report/:month')">7月份报表</el-button>
        </template>
        <!-- 筛选区域 -->
        <template slot="sizer">
          <!-- 部门 -->
          <el-form>
            <div class="department">部门:</div>
            <el-checkbox-group v-model="formData.deptID">
              <el-checkbox v-for="item in departments" :key="item.id" :label="item.name">{{ item.name }}</el-checkbox>
            </el-checkbox-group>
          </el-form>
          <!-- 考勤状态 -->
          <el-form>
            <el-form-item label="考勤状态:">
              <el-radio-group v-model="formData.stateID">
                <el-radio v-for="state in stateData.holidayType" :key="state.id" :label="state.value">{{ state.value }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-form>

        </template>
      </page-tools>
      <!-- 下方表格 -->
      <el-card>
        <!-- 考勤表单 -->
        <template>
          <el-table border fixed="left" :data="tableData" style="width: 100%">
            <el-table-column width="50" type="index" label="序号" />
            <el-table-column width="100" prop="username" label="姓名" />
            <el-table-column width="100" prop="workNumber" label="工号" />
            <el-table-column width="100" prop="departmentName" label="部门" />
            <el-table-column width="100" prop="mobile" label="手机" />
            <el-table-column v-for="(item, index) in tableData[0]?tableData[0].attendanceRecord :[]" :key="item.day" width="100" :label="item.day.slice(4,8)">
              <template slot-scope="{row}" @click="showChangeDialog(item,ind,it)">
                {{ workDate(row.attendanceRecord[index].adtStatu) }}
              </template>
            </el-table-column>
          </el-table>
        </template>
        <!-- 分页组件 -->
        <el-row type="flex" justify="end" align="right" style="height: 60px">
          <el-pagination layout="total, prev, pager, next" :total="11" :page-size="4" @current-change="currentChange" />
        </el-row>
      </el-card>

      <!-- 员工考勤弹窗 -->

      <!-- 提醒弹窗 -->
      <el-dialog title="提醒" :visible="showTips" width="22%" center @close="btnCancel">
        <span>系统将通过邮件与短信的形式，对全体员工中存在旷工的考勤进行提醒，该提醒每月仅可发送 1 次。</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="btnCancel">取 消</el-button>
          <el-button type="primary" @click="btnOKTips">我知道了</el-button>
        </span>
      </el-dialog>

      <!-- 设置弹窗 -->
      <el-dialog title="设置" :visible="showSetting" width="50%" left @close="showSetting = false">
        <!-- tab标签 -->
        <el-tabs v-model="activeName" @tab-click="handleSetting">
          <el-tab-pane label="出勤设置" name="first"><attendanceSetting :show-setting.sync="showSetting" /></el-tab-pane>
          <el-tab-pane label="请假设置" name="second"><leaveSetting :show-setting.sync="showSetting" /></el-tab-pane>
          <el-tab-pane label="扣款设置" name="third"><payOff :show-setting.sync="showSetting" /></el-tab-pane>
          <el-tab-pane label="加班设置" name="fourth"><overTime :show-setting.sync="showSetting" /></el-tab-pane>
        </el-tabs>
      </el-dialog>

      <!-- 员工出勤状态 -->
      <el-dialog title="员工出勤" :visible="isShowAttendance" @close="isShowAttendance = false">
        <el-row type="flex" justify="center">
          <canvas ref="mycanvas" />
        </el-row>
      </el-dialog>

      <template />
    </div>
  </div>
</template>

<script>
import { getDepartments } from '@/api/departments'
import attendanceApi from '@/api/constant/attendance'
import { getAttendancesList } from '@/api/attendances'
import attendanceSetting from './components/attendanceSetting'
import leaveSetting from './components/leaveSetting'
import payOff from './components/payOff'
import overTime from './components/overTime'
export default {
  components: {
    attendanceSetting,
    leaveSetting,
    payOff,
    overTime
  },
  data() {
    return {
      showDialog: false,
      // 员工出勤状态
      isShowAttendance: false,
      // 部门
      departments: [],
      // 考勤状态
      stateData: attendanceApi,
      // 表单数据
      formData: {
        keyword: this.keyword,
        deptID: [], // 性别
        stateID: ''
      },
      page: {
        page: 1,
        pagesize: 10,
        total: 20
      },
      // 表单
      tableData: [],
      // // 导入考勤记录弹窗状态
      // showImportAttendance: false
      // 提醒状态
      showTips: false,
      // 设置状态
      showSetting: false,
      activeName: 'second',
      // 出勤状态 组件
      modifyData: {
        userId: '',
        day: '',
        adtStatu: ''
      }

    }
  },
  created() {
    this.getDepartments()// 考勤列表
    this.getAttendancesList()// 表单列表
  },
  methods: {
    workDate(data) {
      if (data) {
        const obj = attendanceApi.vacationtype.find(item => item.id === String(data))
        return obj.name
      }
    },
    // 获取考勤列表
    async getDepartments() {
      const { depts } = await getDepartments()
      this.departments = depts
    },
    async getAttendancesList() {
      const { data } = await getAttendancesList(this.page)
      this.tableData = data.rows
      console.log(data.rows)
    },

    // 提醒点击事件
    tips() {
      this.showTips = true
    },
    // 提醒 -确认
    btnOKTips() {
      // 提示用户
      this.$message.success('操作成功')
      this.showTips = false
    },
    // 提醒 -确认
    btnCancel() {
      this.showTips = false
    },
    // 设置
    btnOkUpdate() {
      // 提示用户
      this.$message.success('操作成功')
      this.showSetting = false
    },
    // 设置弹窗的tab页切换
    handleSetting(tab, event) {
      // console.log(tab, event)
    },
    // 员工详情点击事件
    showChangeDialog(item, id, it) {
      this.modifyData.userId = item.id
      this.modifyData.day = it.day
      this.modifyData.departmentId = item.departmentId
      this.modifyData.adtStatu = it.adtStatu + '' // 数字转成字符串

      if (it.adtStatu !== '') {
        this.attendInfo.getDate = parseInt(id + 1)
        this.attendInfo.getInfo = it.adtStatu
        this.attendInfo.name = item.name
        this.centerDialogVisible = true
      }
    },

    // 设置点击事件
    setting() {
      this.showSetting = true
    },

    // 员工出勤状态弹窗
    showAttendance() {
      this.isShowAttendance = true
    },

    // 切换页面 分页组件
    currentChange() {}
  }
}
</script>

<style lang="scss" scoped>
// 复选框组样式
.department{
  margin-top: 20px;
  font-size: 14px;
  font-weight: bold;
  color: #666;
}
.el-form-item{
  margin-bottom: 0;
}

</style>
